<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/WEB-TAG/platForm.tld" prefix="PF"%>
<div class="easyui-layout" data-options="fit:true">
	<div class="TableTitle" data-options="region:'north',border:false"
		style="text-align: left;">
		数据库链接向导
	</div>
	<div data-options="region:'center'">
		<div class="demo-info" style="margin: 8px;">
			<div class="demo-tip icon-future-projects"></div>
			<div>
				${project.name}
				<p>
					${project.pcontent}
				</p>
				<p>
					<c:if test="${project.graphid!=null&&project.graphid!=''}">
						<img style="margin: 4px; width: 100%; max-width: 400px;"
							src="admin/FPloadfile.do?id=${project.graphid}">
					</c:if>
				</p>
			</div>
		</div>
		<div class="demo-info" style="margin: 8px;">
			<div class="demo-tip icon-database"></div>
			<div>
				1.数据库链接配置:
				<form id="dom_formJdbc">
					<input type="hidden" name="ids" value="${project.id}">
					<table>
						<tr>
							<td class="title">
								数据库驱动类:
							</td>
							<td colspan="3">
								<input type="text" class="easyui-validatebox"
									style="width: 360px;" data-options="required:true"
									name="entity.dbdriverclass" value="${entity.dbdriverclass}">
							</td>
						</tr>
						<tr>
							<td class="title">
								数据库URL:
							</td>
							<td colspan="3">
								<input type="text" class="easyui-validatebox"
									style="width: 360px;" data-options="required:true"
									name="entity.dburl" value="${entity.dburl}">
							</td>
						</tr>
						<tr>
							<td class="title">
								数据库用户名:
							</td>
							<td colspan="3">
								<input type="text" class="easyui-validatebox"
									style="width: 360px;" data-options="required:true"
									name="entity.dbusername" value="${entity.dbusername}">
							</td>
						</tr>
						<tr>
							<td class="title">
								数据库用户密码:
							</td>
							<td colspan="3">
								<input type="text" class="easyui-validatebox"
									style="width: 360px;" data-options="required:true"
									name="entity.dbpassword" value="${entity.dbpassword}">
							</td>
						</tr>
						<tr>
							<td class="title">
							</td>
							<td colspan="3">
								<a id="dom_add_dbLink" href="javascript:void(0)"
									iconCls="icon-link" class="easyui-linkbutton">测试数据库链接</a>
								<span style="color: green;" id="dababaseInfoId"></span>
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
		<div class="demo-info" style="margin: 8px;">
			<div class="demo-tip icon-settings"></div>
			<div>
				2.设置数据表信息
				<form id="dom_formAppsetings">
					<input type="hidden" name="ids" value="${project.id}">
					<table>
						<tr>
							<td class="title">
								选择数据表:
							</td>
							<td colspan="3">
								<select id="tableSelectINputId" val='${entity.tablename}'
									class="easyui-validatebox" name="entity.tablename"
									data-options="required:true">
									<option value="${entity.tablename}">
										${entity.tablename}
									</option>
								</select>
							</td>
						</tr>
						<tr>
							<td class="title">
								业务标志CODE:
							</td>
							<td colspan="3">
								<input type="text" class="easyui-validatebox"
									style="width: 360px;"
									data-options="required:true,validType:['english']"
									name="entity.appcode" value="${entity.appcode}">
							</td>
						</tr>
						<tr>
							<td class="title">
								CODE随机数:
							</td>
							<td colspan="3">
								<select name="entity.apprandom" val="${entity.apprandom}"
									class="easyui-validatebox" data-options="required:true">
									<option value="0">
										无
									</option>
									<option value="1">
										添加随机数
									</option>
								</select>
							</td>
						</tr>
						<tr>
							<td class="title">
								业务名称:
							</td>
							<td colspan="3">
								<input type="text" class="easyui-validatebox"
									style="width: 360px;" data-options="required:true"
									name="entity.appname" value="${entity.appname}">
							</td>
						</tr>
						<tr>
							<td class="title">
								机构类型:
							</td>
							<td colspan="3">
								<select name="entity.comtype" val="${entity.comtype}"
									class="easyui-validatebox" data-options="required:true">
									<option value="">
										请选择
									</option>
									<option value="com">
										com组织
									</option>
									<option value="org">
										org公司
									</option>
								</select>
							</td>
						</tr>
						<tr>
							<td class="title">
								机构CODE:
							</td>
							<td colspan="3">
								<input type="text" class="easyui-validatebox"
									style="width: 360px;"
									data-options="required:true,validType:['english']"
									name="entity.comcode" value="${entity.comcode}">
							</td>
						</tr>
						<tr>
							<td class="title">
								项目CODE:
							</td>
							<td colspan="3">
								<input type="text" class="easyui-validatebox"
									style="width: 360px;"
									data-options="required:true,validType:['english']"
									name="entity.procode" value="${entity.procode}">
							</td>
						</tr>
						<tr>
							<td class="title">
							</td>
							<td colspan="3">

							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
		<div class="demo-info" style="margin: 8px;">
			<div class="demo-tip icon-publish"></div>
			3.设置数据字段信息
			<div style="margin: 8px;">
				<a id="dom_add_dbset" href="javascript:void(0)" iconCls="icon-save"
					class="easyui-linkbutton">加载数据</a>
				<span style="color: green;" id="dababaseInfoId"></span>
			</div>
			<div>
				<table id="dg" style="width: 800px; height: 350px"></table>
			</div>
			<div style="padding: 8px; text-align: center;">
				<a id="dom_add_submitFields" href="javascript:void(0)"
					iconCls="icon-save" class="easyui-linkbutton">继续</a>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	var submitFormjdbc;
	var submitFormApp;
	var cloumArray = [ [ {
		field : 'TITLE',
		title : '字段名称',
		width : 100,
		editor : {
			type : 'text',
			options : {
				on : '1',
				off : ''
			}
		}
	}, {
		field : 'NAME',
		title : '字段代码',
		width : 100
	}, {
		field : 'TYPE',
		title : '字段类型',
		width : 100
	}, {
		field : 'SIZE',
		title : '字段长度',
		width : 100
	}, {
		field : 'FFORMTYPE',
		title : '表单类型',
		width : 100,
		editor : {
			type : 'combobox',
			options : {
				valueField : 'id',
				textField : 'id',
				url : 'PLUGIN/code/formType.json',
				required : true
			}
		}
	}, {
		field : 'FPK',
		title : '是否主键',
		width : 50,
		editor : {
			type : 'checkbox',
			options : {
				on : '1',
				off : ''
			}
		}
	}, {
		field : 'NULLABLE',
		title : '是否必填',
		width : 50,
		editor : {
			type : 'checkbox',
			options : {
				on : '0',
				off : '1'
			}
		}
	}, {
		field : 'FLIMITTYPE',
		title : '查询条件类型',
		width : 100,
		editor : {
			type : 'combobox',
			options : {
				valueField : 'id',
				textField : 'id',
				url : 'PLUGIN/code/limitType.json',
				required : false
			}
		}
	} ] ];
	$(function() {
		//表单组件对象
		submitFormjdbc = $('#dom_formJdbc').SubmitForm( {
			pageType : "1",
			grid : null,
			currentWindowId : null,
			noStreak : true
		});
		submitFormApp = $('#dom_formAppsetings').SubmitForm( {
			pageType : "1",
			grid : null,
			currentWindowId : null,
			noStreak : true
		})
		$('#dom_add_dbLink').bind(
				'click',
				function() {
					submitFormjdbc.postSubmit(
							"admin/FarmCodeJdbcLinkCommit.do", function(flag) {
								$('#tableSelectINputId').html('');
								$(flag.tables).each(
										function(index, obj) {
											var optionStr = "<option id='"
													+ obj + "'>" + obj
													+ "</option>";
											$('#tableSelectINputId').append(
													optionStr);
										});
								$('#dababaseInfoId').text("链接成功");
							});
				});
		$('#dom_add_dbset')
				.bind(
						'click',
						function() {
							var url_srt = "admin/FarmCodeGuidequeryJdbcFieldsAll.do?ids=${project.id}";
							submitFormApp.postSubmit(
									"admin/FarmCodeAppCommit.do",
									function(flag) {
										$('#dg').datagrid( {
											checkOnSelect : false,
											selectOnCheck : false,
											singleSelect : true,
											onSelect : function() {
												return false;
											},
											onCheck : function() {
												return false;
											},
											url : url_srt,
											columns : cloumArray
										});
									});
							$('#dom_add_submitFields').linkbutton('enable');
							return false;
						});
		$('#dg').datagrid( {
			onLoadSuccess : function(data) {
				$($('#dg').datagrid('getRows')).each(function(index) {
					$('#dg').datagrid('beginEdit', index);
				});
			}
		});
		$('#dom_add_submitFields')
				.bind(
						'click',
						function() {
							$('#dom_add_submitFields').linkbutton('disable');
							$('#dg').datagrid('acceptChanges');
							$($('#dg').datagrid('getRows')).each(
									function(index) {
										$('#dg').datagrid('beginEdit', index);
									});
							var rows = $('#dg').datagrid('getRows')
							$
									.post(
											'admin/FarmCodeGuideFieldCommit.do',
											{
												ids : '${project.id}',
												dataStr : JSON.stringify(rows)
											},
											function() {
												$('#dom_add_submitFields')
														.linkbutton('enable');
												$.farm
														.openWindow( {
															id : 'winfarmcodepackage',
															width : 1000,
															height : 300,
															modal : true,
															url : "admin/FarmCodeGuide_parameter_view.do?ids=${project.id}",
															title : '生成参数'
														});

											});
						});
		$.parser.parse();
		$('#dom_add_submitFields').linkbutton('disable');

	});
	//-->
</script>